package com.hd.boot.service.impl;

import com.hd.boot.mapper.PerMapper;
import com.hd.boot.pojo.Persone;
import com.hd.boot.service.PerService;
import com.hd.boot.util.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class PerServiceImpl implements PerService {
    @Autowired
    private PerMapper perMapper;
    @Override
    public JsonData allPer() {
        List<Persone> persones=perMapper.allPer();
        return JsonData.buildSuccess(persones,"success");
    }

    @Override
    public JsonData delPer(int pId) {
        int i=perMapper.delPer(pId);
        if (i>0){
            return JsonData.buildSuccess("成功");
        }
        return JsonData.buildError("失败");
    }

    @Override
    public JsonData savePer(Persone persone) {
        int i=0;
        if (persone.getpId()==null){
            i=perMapper.savePer(persone);
        }else {

            i=perMapper.enidPer(persone);
        }
        if (i>0){
            return JsonData.buildSuccess("成功");
        }
        return JsonData.buildError("失败");
    }
}
